package com.kinpoway.web.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 *  通过写参数的形式进行切片拦截。
 */
@Aspect
@Component
public class TimeAspect {

    //包围一个切片
    @Around("execution(* com.kinpoway.web.controller.UserController.*(..))")
    public Object handleControllerMethod(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {

        System.out.println("time aspect start");
        Object[] args =  proceedingJoinPoint.getArgs();
        for(Object arg :args){
            System.out.println(arg);
        }
        long start = new Date().getTime();
        Object object = proceedingJoinPoint.proceed();

        System.out.println("time aspect 耗时："+ (new Date().getTime() - start));
        System.out.println("time aspect end");
        return object;
    }


}

